سورس پشته ( Stack )

سورس پشته ( Stack )

جمعه 12 بهمن 1397
10:22
گروه توسعه هوشمند

#include
#include
using namespace std;
#define MAX 11

class Stack {
    int top;
public:
    int a[MAX];    

    Stack() {
        top = -1;
    }
    bool push(int x);
    int pop();
    bool isEmpty();
};

bool Stack::push(int x) {
    if (top >= (MAX - 1)) {
        cout << "Stack Overflow";
        return false;
    }
    else {
        a[++top] = x;
        cout << x << " pushed into stack\n";
        return true;
    }
}

int Stack::pop() {
    if (top < 0) {
        cout << "Stack Underflow";
        return 0;
    }
    else {
        int x = a[top--];
        return x;
    }
}

bool Stack::isEmpty() {
    return (top < 0);
}


int main() {
    cout << "********************************************************" << endl;
    cout << "             smartdevelop.ir" << endl;
    cout << "********************************************************" << endl;
    struct Stack s;
    int shomare;
    for (int i = 0;i <= 10;i++) {
        cout << "adad somare " << i << " ra vared konid :";
        cin >> shomare;
        s.push(shomare);
    }
    for (int i = 0;i <= 10;i++) {
        cout << s.pop() << " Popped from stack\n";
    }
    getch();

    return 0;
}

 

 

از کتابخانه های  iostream  و  conio.h  استفاه کنید

سورس : دانلود

 

 

 

 

 

 

 

 

 

 


نظرات شما عزیزان:

نام :
آدرس ایمیل:
وب سایت/بلاگ :
متن پیام:
:) :( ;) :D
;)) :X :? :P
:* =(( :O };-
:B /:) =DD :S
-) :-(( :-| :-))
نظر خصوصی

 کد را وارد نمایید:

 

 

 

عکس شما

آپلود عکس دلخواه:






موضوعات مرتبط: ++C